package com.example.s10shoppingthymeleaf.controller;


import com.example.s10shoppingthymeleaf.entity.Goods;
import com.example.s10shoppingthymeleaf.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

@Controller
public class GoodsController {
    @Autowired
    GoodsService goodsService;
    @GetMapping("/allGoods")
    @ResponseBody
    public String getAllGoods(){
        List<Goods> goodsList =goodsService.getAllGoods();
        return goodsList.toString();
    }
    @GetMapping("/index")
    public  String index(Model model) {
        List<Goods> goodsList = goodsService.getAllGoods();
        model.addAttribute("goodslist",goodsList);
        return "index";
    }

}
